import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')
import django
django.setup()
from web.models import Category,Topic


def add():
    c = Category()
    c.name = "test"
    c.type = 0
    c.is_nav = True
    c.orders = 10
    c.save()


def update():
    c = Category.objects.get(id=1)
    c.type = 1
    c.save()


def delete():
    c = Category.objects.get(id=3)
    c.delete()


def load():
    return Category.objects.get(id=1)

def find():
    return Category.objects.all()


if __name__ == '__main__':
    # add()
    # update()
    # delete()
    # c = load()
    # print(c.name)
    for c in find():
        print(c.name)
        print(c.category_set.all())
        print(c.parent)